<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    
    <title>Kakao login</title>
<script src="/resources/js/jquery-1.11.0.js"></script>
<script src="https://developers.kakao.com/sdk/js/kakao.min.js"></script>
<script type="text/javascript">
	Kakao.init('c5f8d437c21941d011d7e542f02b91dc');
	
	function init(){
		Kakao.Auth.login({
	    	success: function(authObj) {
	    		alert(JSON.stringify(authObj));
	    		Kakao.API.request({
	    	        url: '/v1/user/me',
	    	        success: function(res) {
	    	        	var data = 'kakao-idx='+res.id+'&kakao-nickname='+res.properties.nickname+'&kakao-profile_image='+res.properties.profile_image;
	    	        	$.ajax({
	                		type : "POST"
	            		    , url : "/kakaoLogin"
	            		    , data : data
	            		    , dataType : "text"
	            		    , timeout : 5000
	            		    , error : function(request, status, error) {
	            		    	alert('d');
	            		    }
	            		    , success : function(response) {
	            		    	if(response == "login"){
	            		    		location.href= "/";
	            		    	}else if(response == "sign"){
	            		    		location.href= '/start_guide';
	            		    	}else{
	            		    		alert('d');
	            		    	}
	            		    }
	            		    , beforeSend: function() {
	            		    	
	            		    }
	            		    , complete: function() {
	            		    	
	            		    }
	            		});
	    	        }
	    	    });
	    	}
	    });
	}
</script>
</head>
<body onload="init();">
</body>
</html>